/**
 * 回款的站内消息监听
 */
package com.p2p.front.jms.consumer.news;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.p2p.base.model.MailTemplate;
import com.p2p.base.service.EmailService;
import com.p2p.front.dal.model.TenderReturn;
import com.p2p.front.mail.TenderMailTemplate;
import com.p2p.front.service.impl.MemberPointServiceImpl;

/**
 * @author ruiqi
 *
 */
public class NewsTenderReturnListener implements MessageListener{

	private final Logger logger = LoggerFactory.getLogger(NewsTenderReturnListener.class);
	
	@Resource
	EmailService emailService;
	

	
	@Override
	public void onMessage(Message message) {
		TenderReturn tenderReturn = null;
		//System.out.println("您有一笔还款到帐，金额=");
		ObjectMessage objMsg = (ObjectMessage) message;
		try {
			Object o = objMsg.getObject();
			tenderReturn = (TenderReturn) o;
		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		logger.info("TenderReturn message id="+ tenderReturn.getId());
		
		
		MailTemplate mailTemplate = MailTemplate.getTemplate(TenderMailTemplate.name);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("amount", tenderReturn.getAmount());
		
		Map<String,File> attachMap = new HashMap<String,File>();
		
		emailService.sendEmail(mailTemplate, "xxxxx@cccc.com", map,attachMap);
		
		System.out.println("您有一笔还款到帐，金额="+tenderReturn.getAmount());
	}

}
